package com.plate.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.plate.common.datasource.base.MyBaseServiceImpl;
import com.plate.modules.system.domain.po.SysUserRole;
import com.plate.modules.system.mapper.SysUserRoleMapper;
import com.plate.modules.system.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName SysUserRoleServiceImpl
 * @Description TODO
 * @Author jiaxd
 * @Date 2023年10月23日 23:01
 * @Version 1.0
 */

@Service
public class SysUserRoleServiceImpl extends MyBaseServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;


    @Override
    public void removeBatch(Long roleId, List<String> collect) {
        sysUserRoleMapper.deleteBatch(roleId, collect);
    }

    @Override
    public List<Long> listByRoleId(Long roleId) {
        LambdaQueryWrapper<SysUserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysUserRole::getRoleId, roleId);
        return sysUserRoleMapper.selectList(wrapper).stream().map(x -> x.getUserId()).collect(Collectors.toList());
    }

    @Override
    public boolean delete(Long roleId, Long userId) {
        return sysUserRoleMapper.delete(roleId, userId);
    }

    @Override
    public int saveBatch(List<SysUserRole> list) {
        return sysUserRoleMapper.batchUserRole(list);
    }

}
